package org.come.Jpanel;

import org.come.Frame.TestpackJframe;

import java.awt.event.MouseEvent;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.Color;
import javax.swing.BorderFactory;

import com.tool.tcpimg.UIUtils;
import com.updateNew.MyIsif;

import java.awt.event.MouseListener;
import java.awt.Component;

import org.come.until.*;

import java.awt.image.ImageObserver;

import com.tool.role.RoleProperty;
import org.come.Frame.ZhuFrame;

import java.awt.Graphics;
import javax.swing.Icon;
import java.awt.Dimension;
import javax.swing.ImageIcon;

import org.come.entity.Goodstable;
import com.tool.tcpimg.RichLabel;

import java.math.BigDecimal;
import javax.swing.JTextField;
import javax.swing.JLabel;

import com.tool.btn.GemRefineryBtn;

import javax.swing.JPanel;



public class GemRefineryMainJpanel extends JPanel {
    private GemRefineryBtn btnCompound;
    private GemRefineryBtn btnDisassembly;
    private GemRefineryBtn btnTrepanning;
    private GemRefineryBtn btnCaozuo;
    private GemRefineryBtn btnLock;
    private GemRefineryBtn btnUnlock;
    private GemRefineryBtn btnLastPage;
    private GemRefineryBtn btnNextPage;
    private GemRefineryBtn btnCaozuoCompound;
    private GemRefineryBtn btnCaozuoDisassembly;
    private JLabel[] labsGoods;
    private JLabel labMaterials;
    private JLabel labProduct;
    private JTextField textNum;
    private BigDecimal money;
    private RichLabel richMsg;
    private Goodstable chooseGoodstable;
    private Goodstable twoGoodstable;
    private int gemNum;
    private int gemBackNum;
    private int lvlNum;
    private int type;
    private int page;
    private ImageIcon icon;
    private ImageIcon rightIcon;
    private ImageIcon gemBackImg;
    private ImageIcon gemImg;

    public GemRefineryMainJpanel() {
        this.type = -1;
        this.page = 0;
        this.setPreferredSize(new Dimension(558, 516));
        this.setLayout(null);
        this.setOpaque(false);
        this.getBtnCompound();
        this.getBtnDisassembly();
        this.getLabsGoods();
        this.getTextNum();
        this.getLabProduct();
        this.getLabMaterials();
        this.getRichMsg();
        this.getBtnTrepanning();
        this.getBtnNextPage();
        this.getBtnLastPage();
        this.getBtnLock();
        this.getBtnUnlock();
        this.getBtnCaozuoDisassembly();
        this.getBtnCaozuoCompound();
    }

    public void initView(final int num) {
        if (num == -1) {
            if (this.type == -1) {
                this.type = 0;
            }
            this.changeMainView(true);
            return;
        }
        this.changeMainView(false);
        this.type = num;
        this.changeMainView(true);
    }

    public void changeMainView(final boolean bo) {
        if (bo) {
            this.page = 0;
            this.textNum.setText("0");
            this.chooseGoodstable = null;
            this.richMsg.setText(null);
            this.gemBackNum = 0;
            this.gemNum = 0;
            this.refreshLeftGoods();
        }
        if (this.type == 0) {
            this.changeCompoundView(bo);
        } else if (this.type == 1) {
            this.changeForgeView(bo);
        } else if (this.type == 2) {
            this.changeTrepanningView(bo);
        }
    }

    public void refreshLeftGoods() {
        try {
            if (MyIsif.getStyle().equals("水墨UI")) {
                if (getChooseGoods(21) == null) {
                    if (btnNextPage.getBtn() != -1) {
                        btnNextPage.setIcon(CutButtonImage.getImage("skin/8100226/button/60.png", -1, -1));
                        btnNextPage.setBtn(-1);
                    }
                } else {
                    if (btnNextPage.getBtn() != 1) {
                        btnNextPage.setBtn(1);
                        btnNextPage.setIcons(CutButtonImage.cuts("skin/8100226/button/9.png"));
                    }
                }
                if (page <= 0) {
                    if (btnLastPage.getBtn() != -1) {
                        btnLastPage.setBtn(-1);
                        btnLastPage.setIcon(CutButtonImage.getImage("skin/8100226/button/61.png", -1, -1));
                    }
                } else {
                    if (btnLastPage.getBtn() != 1) {
                        btnLastPage.setBtn(1);
                        btnLastPage.setIcons(CutButtonImage.cuts("skin/8100226/button/10.png"));
                    }
                }
            } else {
                if (this.getChooseGoods(21) == null) {
                    if (this.btnNextPage.getBtn() != -1) {
                        this.btnNextPage.setIcon((Icon) CutButtonImage.getImage("inkImg/hongmu/2/36_png.button.btn_7.png", -1, -1));
                        this.btnNextPage.setBtn(-1);
                    }
                } else if (this.btnNextPage.getBtn() != 1) {
                    this.btnNextPage.setBtn(1);
                    this.btnNextPage.setIcons(CutButtonImage.cuts("inkImg/hongmu/2/36_png.button.btn_7.png"));
                }
                if (this.page <= 0) {
                    if (this.btnLastPage.getBtn() != -1) {
                        this.btnLastPage.setBtn(-1);
                        this.btnLastPage.setIcon((Icon) CutButtonImage.getImage("inkImg/hongmu/2/30_png.button.btn_8.png", -1, -1));
                    }
                } else if (this.btnLastPage.getBtn() != 1) {
                    this.btnLastPage.setBtn(1);
                    this.btnLastPage.setIcons(CutButtonImage.cuts("inkImg/hongmu/2/30_png.button.btn_8.png"));
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public Goodstable getChooseGoods(final int numPlace) {
        final Goodstable[] goodslist = GoodsListFromServerUntil.getGoodslist();
        int num = 0;
        for (int i = 0; i < goodslist.length; ++i) {
            final Goodstable goodstable = goodslist[i];
            if (goodstable != null) {
                if (this.type == 0) {
                    if (!Goodtype.isGemRefining(goodstable.getType().longValue())) {
                        continue;
                    }
                } else if (!Goodtype.EquipGem(goodstable.getType().longValue())) {
                    continue;
                }
                if (this.page * 21 > num) {
                    ++num;
                } else {
                    if (num - this.page * 21 == numPlace) {
                        return goodstable;
                    }
                    ++num;
                }
            }
        }
        return null;
    }

    public void drawGoodsImg(final Graphics g) {
        final Goodstable[] goodslist = GoodsListFromServerUntil.getGoodslist();
        int num = 0;
        if (MyIsif.getStyle().equals("水墨UI")) {
            for (int i = 0; i < goodslist.length; i++) {
                Goodstable goodstable = goodslist[i];
                if (goodstable == null) {
                    continue;
                }
                if (type == 0) {
                    if (!Goodtype.isGemRefining(goodstable.getType())) {
                        continue;
                    }
                } else {
                    if (!Goodtype.EquipGem(goodstable.getType())) {
                        continue;
                    }
                }
                if (page * 21 > num) {
                    num++;
                    continue;
                }
                g.drawImage(GoodsListFromServerUntil.imgpath2(goodstable.getSkin()).getImage(),
                        64 + (num - page * 21) % 3 * 51, 114 + (num - page * 21) / 3 * 51, 43, 43, null);
                if (!EquipTool.isEquip(goodstable.getType())) {
                    g.drawString(goodstable.getUsetime().toString(), 64 + (num - page * 21) % 3 * 51,
                            124 + (num - page * 21) / 3 * 51);
                }

                num++;
                if (num >= (page + 1) * 21) {
                    break;
                }
            }
            if (chooseGoodstable != null) {
                if (type == 0) {
                    g.drawImage(GoodsListFromServerUntil.imgpath2(chooseGoodstable.getSkin()).getImage(), 122 + 230,
                            51 + 110, 43, 43, null);
                    g.drawString(chooseGoodstable.getUsetime().toString(), 120 + 230, 61 + 110);
                    g.drawImage(
                            GoodsListFromServerUntil.imgpath2((chooseGoodstable.getSkin().substring(0, 4)) + (lvlNum + 1))
                                    .getImage(), 122 + 230, 151 + 110, 43, 43, null);
                } else {
                    g.drawImage(GoodsListFromServerUntil.imgpath2(chooseGoodstable.getSkin()).getImage(), 122 + 230,
                            51 + 110, 43, 43, null);
                }
                if (twoGoodstable != null) {
                    g.drawImage(GoodsListFromServerUntil.imgpath2(twoGoodstable.getSkin()).getImage(), 122 + 230,
                            151 + 110, 43, 43, null);
                    g.drawString(twoGoodstable.getUsetime().toString(), 120 + 230, 161 + 110);
                }
            }
        } else {
            for (int i = 0; i < goodslist.length; ++i) {
                final Goodstable goodstable = goodslist[i];
                if (goodstable != null) {
                    if (this.type == 0) {
                        if (!Goodtype.isGemRefining(goodstable.getType().longValue())) {
                            continue;
                        }
                    } else if (!Goodtype.EquipGem(goodstable.getType().longValue())) {
                        continue;
                    }
                    if (this.page * 21 > num) {
                        ++num;
                    } else {
                        g.drawImage(GoodsListFromServerUntil.imgpath2(goodstable.getSkin()).getImage(), 40 + (num - this.page * 21) % 3 * 51, 126 + (num - this.page * 21) / 3 * 51, 43, 43, null);
                        if (!EquipTool.isEquip(goodstable.getType())) {
                            g.drawString(goodstable.getUsetime().toString(), 40 + (num - this.page * 21) % 3 * 51, 136 + (num - this.page * 21) / 3 * 51);
                        }
                        if (++num >= (this.page + 1) * 21) {
                            break;
                        }
                    }
                }
            }
            if (this.chooseGoodstable != null) {
                if (this.type == 0) {
                    g.drawImage(GoodsListFromServerUntil.imgpath2(this.chooseGoodstable.getSkin()).getImage(), 328, 173, 43, 43, null);
                    g.drawString(this.chooseGoodstable.getUsetime().toString(), 325, 280);
        			g.drawImage(GoodsListFromServerUntil.imgpath2(this.chooseGoodstable.getSkin().substring(0, 4) + (this.lvlNum + 1)).getImage(), 328, 273, 43, 43, null);
                } else {
                    g.drawImage(GoodsListFromServerUntil.imgpath2(this.chooseGoodstable.getSkin()).getImage(), 328, 173, 43, 43, null);
                }
                if (this.twoGoodstable != null) {
                    g.drawImage(GoodsListFromServerUntil.imgpath2(this.twoGoodstable.getSkin()).getImage(), 328, 273, 43, 43, null);
                    g.drawString(this.twoGoodstable.getUsetime().toString(), 328, 283);
                }
            }
        }
    }

    public void changeCompoundView(final boolean bo) {
        if (bo) {
            if (MyIsif.getStyle().equals("水墨UI")) {
                rightIcon = CutButtonImage.getImage("inkImg/newbackground/B264.png", -1, -1);
                btnCaozuoCompound.setText("合成");
                btnCaozuoCompound.setBounds(334, 402, 80, 78);
                richMsg.setBounds(265, 123, 260, 20);
            } else {
                this.rightIcon = CutButtonImage.getImage("inkImg/hongmu/2/gemCom.png", -1, -1);
                this.btnCaozuoCompound.setText("合成");
                this.btnCaozuoCompound.setBounds(334, 412, 85, 78);
                this.richMsg.setBounds(240, 323, 260, 20);
            }
        }
        this.textNum.setVisible(bo);
    }

    public void changeForgeView(final boolean bo) {
        if (bo) {
            if (MyIsif.getStyle().equals("水墨UI")) {
                rightIcon = CutButtonImage.getImage("inkImg/newbackground/B263.png", -1, -1);
                btnCaozuoCompound.setText("镶嵌");
                btnCaozuoCompound.setBounds(280, 402, 80, 78);
                richMsg.setBounds(265, 123, 250, 20);
            } else {
                this.rightIcon = CutButtonImage.getImage("inkImg/hongmu/2/gemCaozuo.png", -1, -1);
                this.btnCaozuoCompound.setText("镶嵌");
                this.btnCaozuoCompound.setBounds(280, 422, 85, 78);
                this.richMsg.setBounds(255, 355, 250, 20);
            }
        }
        this.btnCaozuoDisassembly.setVisible(bo);
    }

    public void changeTrepanningView(final boolean bo) {
        if (bo) {
            if (MyIsif.getStyle().equals("水墨UI")) {
                rightIcon = CutButtonImage.getImage("inkImg/newbackground/B263.png", -1, -1);
                btnCaozuoCompound.setText("开孔");
                btnCaozuoCompound.setBounds(334, 402, 80, 78);
            } else {
                this.rightIcon = CutButtonImage.getImage("inkImg/hongmu/2/gemCaozuo.png", -1, -1);
                this.btnCaozuoCompound.setText("开孔");
                this.btnCaozuoCompound.setBounds(334, 422, 85, 78);
            }
        }
    }

    public void drawGemBackImg(final Graphics g, final int num, final int gemNum) {
        if (MyIsif.getStyle().equals("水墨UI")) {
            if (gemBackImg == null) {
                gemBackImg = CutButtonImage.getImage("inkImg/hongmu/2/gemBackImg.png", -1, -1);
            }
            if (gemImg == null) {
                gemImg = CutButtonImage.getImage("inkImg/hongmu/2/gemImg.png", -1, -1);
            }
            for (int i = 0; i < num; i++) {
                g.drawImage(gemBackImg.getImage(), 230 + 144 - num / 2 * 13 + (i * 13), 326, 10, 16, null);
                if (i < gemNum)
                    g.drawImage(gemImg.getImage(), 230 + 145 - num / 2 * 13 + (i * 13), 327, 8, 14, null);
            }
        } else {
            if (this.gemBackImg == null) {
                this.gemBackImg = CutButtonImage.getImage("inkImg/hongmu/2/gemBackImg.png", -1, -1);
            }
            if (this.gemImg == null) {
                this.gemImg = CutButtonImage.getImage("inkImg/hongmu/2/gemImg.png", -1, -1);
            }
            for (int i = 0; i < num; ++i) {
                g.drawImage(this.gemBackImg.getImage(), 374 - num / 2 * 13 + i * 13, 326, 10, 16, null);
                if (i < gemNum) {
                    g.drawImage(this.gemImg.getImage(), 375 - num / 2 * 13 + i * 13, 327, 8, 14, null);
                }
            }
        }
    }

    public Goodstable getLvlGem(final int lvlGem) {
        final Goodstable[] goodslist = GoodsListFromServerUntil.getGoodslist();
        for (int i = 0, length = goodslist.length; i < length; ++i) {
            final Goodstable goodstable = goodslist[i];
            if (this.type == 1) {
                final int equipmentType = Goodtype.EquipmentType(this.chooseGoodstable.getType().longValue());
                if (equipmentType < 0) {
                    return null;
                }
                if (goodstable != null && Goodtype.isGemRefiningType(goodstable.getType().longValue()) == equipmentType && Integer.parseInt(goodstable.getValue().substring(3)) == lvlGem) {
                    return goodstable;
                }
            } else {
                if (this.type != 2) {
                    return null;
                }
                if (goodstable != null && Goodtype.isGemTapanning(goodstable.getType().longValue())) {
                    return goodstable;
                }
            }
        }
        return null;
    }

    public void addChooseGoods(final Goodstable goodstable) {
        if (goodstable != null) {
            if (this.type == 0) {
                this.lvlNum = Integer.parseInt(goodstable.getValue().substring(3));
                final Integer usetime = goodstable.getUsetime();
                if (this.lvlNum == 5) {
                    ZhuFrame.getZhuJpanel().addPrompt2("已经是最高级宝石了");
                    return;
                }
                final int con = 10 - (this.lvlNum - 1) * 2;
                final StringBuffer buffer = new StringBuffer();
                buffer.append("#G合成一个#R");
                buffer.append(this.lvlNum + 1);
                buffer.append("级#G的宝石需要#R");
                buffer.append(con);
                buffer.append("#G颗的#R");
                buffer.append(this.lvlNum);
                buffer.append("级#G的宝石");
                this.richMsg.setText(buffer.toString());
                final int num = usetime.intValue() / con;
                this.chooseGoodstable = goodstable;
                this.textNum.setText(String.valueOf(num));
            } else if (this.type == 1) {
                Integer qht = goodstable.getQht();
                qht = Integer.valueOf((qht == null) ? 0 : qht.intValue());
                Integer qhv = goodstable.getQhv();
                qhv = Integer.valueOf((qhv == null) ? 0 : qhv.intValue());
                this.gemBackNum = qht.intValue();
                this.gemNum = qhv.intValue();
                this.chooseGoodstable = goodstable;
                this.richMsg.setText(this.getrichMsgStr(this.gemNum, this.gemBackNum));
                this.money = new BigDecimal((this.gemNum / 3 + 1) * 1000000);
            } else if (this.type == 2) {
                if (Goodtype.isGemTapanning(goodstable.getType().longValue())) {
                    if (this.chooseGoodstable != null) {
                        this.twoGoodstable = goodstable;
                    }
                    return;
                }
                Integer qht = goodstable.getQht();
                qht = Integer.valueOf((qht == null) ? 0 : qht.intValue());
                Integer qhv = goodstable.getQhv();
                qhv = Integer.valueOf((qhv == null) ? 0 : qhv.intValue());
                if (qht.intValue() >= 15) {
                    ZhuFrame.getZhuJpanel().addPrompt2("开孔已经抵达上限");
                    return;
                }
                this.chooseGoodstable = goodstable;
                this.gemBackNum = qht.intValue();
                this.gemNum = qhv.intValue();
                this.money = new BigDecimal(1000000);
            }
            this.twoGoodstable = this.getLvlGem(this.gemNum / 3 + 1);
        }
    }

    public void refreshChooseGoodstable(final Goodstable goodstable, final int oneTwo) {
        if (oneTwo == 1) {
            if (goodstable.getUsetime().intValue() <= 0) {
                this.chooseGoodstable = null;
                this.twoGoodstable = null;
                this.gemBackNum = 0;
                this.gemNum = 0;
                this.richMsg.setText(null);
                this.textNum.setText("0");
                return;
            }
            this.chooseGoodstable = goodstable;
            if (this.type == 0) {
                final int num = goodstable.getUsetime().intValue() / (10 - (this.lvlNum - 1) * 2);
                this.textNum.setText(String.valueOf(num));
            } else if (this.type == 1) {
                this.gemBackNum = ((this.chooseGoodstable.getQht() == null) ? 0 : this.chooseGoodstable.getQht().intValue());
                this.gemNum = ((this.chooseGoodstable.getQhv() == null) ? 0 : this.chooseGoodstable.getQhv().intValue());
                this.richMsg.setText(this.getrichMsgStr(this.gemNum, this.gemBackNum));
                this.money = new BigDecimal((this.gemNum / 3 + 1) * 1000000);
            } else if (this.type == 2) {
                this.gemBackNum = ((this.chooseGoodstable.getQht() == null) ? 0 : this.chooseGoodstable.getQht().intValue());
                this.gemNum = ((this.chooseGoodstable.getQhv() == null) ? 0 : this.chooseGoodstable.getQhv().intValue());
            }
            this.twoGoodstable = this.getLvlGem(this.gemNum / 3 + 1);
        } else if (oneTwo == 2) {
            if (this.chooseGoodstable != null) {
                if (this.type == 1) {
                    if (Goodtype.EquipmentType(this.chooseGoodstable.getType().longValue()) == Goodtype.isGemRefiningType(goodstable.getType().longValue()) && this.gemNum / 3 + 1 == Integer.parseInt(goodstable.getValue().substring(3))) {
                        this.twoGoodstable = goodstable;
                    }
                } else if (this.type == 2 && Goodtype.isGemTapanning(goodstable.getType().longValue())) {
                    if (goodstable.getUsetime().intValue() <= 0) {
                        this.twoGoodstable = null;
                    } else {
                        this.twoGoodstable = goodstable;
                    }
                }
            } else {
                this.twoGoodstable = null;
            }
        }
        this.refreshLeftGoods();
    }

    public String getrichMsgStr(final int gemNum, final int gemBackNum) {
        final StringBuffer buffer = new StringBuffer();
        buffer.append("#R基础属性+");
        buffer.append(String.format("%.2f", Double.valueOf(RoleProperty.getQHGemXS(gemNum))));
        if (gemNum >= 15) {
            buffer.append("%,已达到最高等级");
        } else if (gemNum >= gemBackNum) {
            buffer.append("%,开孔后可继续强化");
        } else {
            buffer.append("%,下一阶段属性#B+");
            buffer.append(String.format("%.2f", Double.valueOf(RoleProperty.getQHGemXS(gemNum + 1))));
            buffer.append("%");
        }
        return buffer.toString();
    }

    @Override
    protected void paintComponent(final Graphics g) {
        super.paintComponent(g);
        if (MyIsif.getStyle().equals("水墨UI")) {
            if (icon == null) {
                icon = new ImageIcon("inkImg/newbackground/B262.png");
            }
            g.drawImage(icon.getImage(), 46, 74, this);

            if (rightIcon != null)
                g.drawImage(rightIcon.getImage(), 230, 113, this);
            if (type == 0) {
                if (money != null)
                    Util.drawPrice(g, money, 337, 377);
                Util.drawMoney(g, 337, 403);
            } else {
                if (money != null)
                    Util.drawPrice(g, money, 337, 377);
                Util.drawMoney(g, 337, 403);
                drawGemBackImg(g, gemBackNum, gemNum);
            }
        } else {
            if (this.icon == null) {
                this.icon = new ImageIcon("inkImg/hongmu/2/gemMain.png");
            }
            g.drawImage(this.icon.getImage(), 22, 86, (ImageObserver) this);
            if (this.rightIcon != null) {
                g.drawImage(this.rightIcon.getImage(), 206, 122, (ImageObserver) this);
            }
            if (this.type == 0) {
                if (this.money != null) {
                    Util.drawPrice(g, this.money, 335, 397);
                }
                Util.drawMoney(g, 335, 423);
            } else {
                if (this.money != null) {
                    Util.drawPrice(g, this.money, 335, 412);
                }
                Util.drawMoney(g, 335, 438);
                this.drawGemBackImg(g, this.gemBackNum, this.gemNum);
            }
        }
        this.drawGoodsImg(g);
    }

    public GemRefineryBtn getBtnCompound() {
        if (this.btnCompound == null) {
            if (MyIsif.getStyle().equals("水墨UI")) {
                btnCompound = new GemRefineryBtn("skin/8100226/newbutton/K38.png", 1, 0, this);
                btnCompound.setBounds(55, 49, 90, 24);
                this.add(btnCompound);
            } else {
                (this.btnCompound = new GemRefineryBtn("inkImg/hongmu/2/setsynthesis_1.png", 1, 0, this)).setBounds(31, 60, 86, 26);
                this.add((Component) this.btnCompound);
            }
        }
        return this.btnCompound;
    }

    public void setBtnCompound(final GemRefineryBtn btnCompound) {
        this.btnCompound = btnCompound;
    }

    public GemRefineryBtn getBtnDisassembly() {
        if (this.btnDisassembly == null) {
            if (MyIsif.getStyle().equals("水墨UI")) {
                btnDisassembly = new GemRefineryBtn("skin/8100226/newbutton/K49.png", 1, 1, this);
                btnDisassembly.setBounds(55 + 92, 49, 90, 24);
            } else {
                (this.btnDisassembly = new GemRefineryBtn("inkImg/hongmu/2/unGemInlay.png", 1, 1, this)).setBounds(119, 60, 86, 26);
            }

            this.add((Component) this.btnDisassembly);
        }
        return this.btnDisassembly;
    }

    public void setBtnDisassembly(final GemRefineryBtn btnDisassembly) {
        this.btnDisassembly = btnDisassembly;
    }

    public ImageIcon getIcon() {
        return this.icon;
    }

    public void setIcon(final ImageIcon icon) {
        this.icon = icon;
    }

    public GemRefineryBtn getBtnCaozuo() {
        return this.btnCaozuo;
    }

    public void setBtnCaozuo(final GemRefineryBtn btnCaozuo) {
        this.btnCaozuo = btnCaozuo;
    }

    public GemRefineryBtn getBtnLock() {
        if (this.btnLock == null) {
            if (MyIsif.getStyle().equals("水墨UI")) {
                btnLock = new GemRefineryBtn("skin/8100226/newbutton/K156.png", 1, 5, this);
                btnLock.setBounds(72, 469, 18, 18);
            } else {
                (this.btnLock = new GemRefineryBtn("inkImg/hongmu/2/25_png.button.btn_lock.png", 1, 5, this)).setBounds(48, 481, 19, 20);
            }
            this.add((Component) this.btnLock);
        }
        return this.btnLock;
    }

    public void setBtnLock(final GemRefineryBtn btnLock) {
        this.btnLock = btnLock;
    }

    public GemRefineryBtn getBtnUnlock() {
        if (this.btnUnlock == null) {
            if (MyIsif.getStyle().equals("水墨UI")) {
                btnUnlock = new GemRefineryBtn("skin/8100226/newbutton/K157.png", 1, 6, this);
                btnUnlock.setBounds(98, 469, 18, 18);
            } else {
                (this.btnUnlock = new GemRefineryBtn("inkImg/hongmu/2/28_png.button.btn_unlock.png", 1, 6, this)).setBounds(74, 481, 19, 20);
            }
            this.add((Component) this.btnUnlock);
        }
        return this.btnUnlock;
    }

    public void setBtnUnlock(final GemRefineryBtn btnUnlock) {
        this.btnUnlock = btnUnlock;
    }

    public GemRefineryBtn getBtnLastPage() {
        if (this.btnLastPage == null) {
            if (MyIsif.getStyle().equals("水墨UI")) {
                btnLastPage = new GemRefineryBtn("skin/8100226/button/10.png", 1, 3, this);
                btnLastPage.setBounds(158, 469, 18, 18);
            } else {
                (this.btnLastPage = new GemRefineryBtn("inkImg/hongmu/2/30_png.button.btn_8.png", 1, 3, this)).setBounds(134, 481, 19, 20);
            }
            this.add((Component) this.btnLastPage);
        }
        return this.btnLastPage;
    }

    public void setBtnLastPage(final GemRefineryBtn btnLastPage) {
        this.btnLastPage = btnLastPage;
    }

    public GemRefineryBtn getBtnNextPage() {
        if (this.btnNextPage == null) {
            if (MyIsif.getStyle().equals("水墨UI")) {
                btnNextPage = new GemRefineryBtn("skin/8100226/button/9.png", 1, 4, this);
                btnNextPage.setBounds(185, 469, 18, 18);
            } else {
                (this.btnNextPage = new GemRefineryBtn("inkImg/hongmu/2/36_png.button.btn_7.png", 1, 4, this)).setBounds(161, 481, 19, 20);
            }
            this.add((Component) this.btnNextPage);
        }
        return this.btnNextPage;
    }

    public void setBtnNextPage(final GemRefineryBtn btnNextPage) {
        this.btnNextPage = btnNextPage;
    }

    public JLabel[] getLabsGoods() {
        if (this.labsGoods == null) {
            this.labsGoods = new JLabel[21];
            if (MyIsif.getStyle().equals("水墨UI")) {
                for (int i = 0; i < labsGoods.length; i++) {
                    labsGoods[i] = new JLabel();
                    labsGoods[i].setBounds(61 + i % 3 * 51, 111 + i / 3 * 51, 50, 50);
                    labsGoods[i].addMouseListener(new MListener(i));
                    this.add(labsGoods[i]);
                }
            } else {
                for (int i = 0; i < this.labsGoods.length; ++i) {
                    (this.labsGoods[i] = new JLabel()).setBounds(37 + i % 3 * 51, 123 + i / 3 * 51, 50, 50);
                    this.labsGoods[i].addMouseListener((MouseListener) new MListener(i));
                    this.add((Component) this.labsGoods[i]);
                }
            }
        }
        return this.labsGoods;
    }

    public void setLabsGoods(final JLabel[] labsGoods) {
        this.labsGoods = labsGoods;
    }

    public JLabel getLabMaterials() {
        if (MyIsif.getStyle().equals("水墨UI")) {
            if (labMaterials == null) {
                labMaterials = new JLabel();
                labMaterials.setBounds(122 + 230, 161, 43, 43);
                labMaterials.addMouseListener(new MListener(-1));
                this.add(labMaterials);
            }
        } else {
            if (this.labMaterials == null) {
                (this.labMaterials = new JLabel()).setBounds(328, 173, 43, 43);
                this.labMaterials.addMouseListener((MouseListener) new MListener(-1));
                this.add((Component) this.labMaterials);
            }
        }
        return this.labMaterials;
    }

    public void setLabMaterials(final JLabel labMaterials) {
        this.labMaterials = labMaterials;
    }

    public JLabel getLabProduct() {
        if (MyIsif.getStyle().equals("水墨UI")) {
            if (labProduct == null) {
                labProduct = new JLabel();
                labProduct.setBounds(122 + 230, 261, 43, 43);
                labProduct.addMouseListener(new MListener(-2));
                this.add(labProduct);
            }
        } else {
            if (this.labProduct == null) {
                (this.labProduct = new JLabel()).setBounds(328, 273, 43, 43);
                this.labProduct.addMouseListener((MouseListener) new MListener(-2));
                this.add((Component) this.labProduct);
            }
        }
        return this.labProduct;
    }

    public void setLabProduct(final JLabel labProduct) {
        this.labProduct = labProduct;
    }

    public JTextField getTextNum() {
        if (MyIsif.getStyle().equals("水墨UI")) {
            if (textNum == null) {
                // 可输入数量
                textNum = new JTextField("0");
                textNum.setBounds(337, 337, 115, 16);
                textNum.setFont(UIUtils.TEXT_FONT1);
                textNum.setOpaque(false);
                textNum.setBorder(BorderFactory.createEmptyBorder());
                textNum.setCaretColor(Color.white);
                textNum.setForeground(Color.white);
                textNum.addKeyListener(new KeyListener() {
                    @Override
                    public void keyTyped(KeyEvent e) {
                        int charstr = e.getKeyChar();
                        String str = textNum.getText();
                        if (str.length() == 0) {
                            textNum.setText(0 + "");
                            return;
                        }
                        // control the value between 0 and 9
                        if (charstr < KeyEvent.VK_0 || charstr > KeyEvent.VK_9) {
                            e.consume();
                        }
                        if (str.length() == 1) {
                            if (str.equals("0")) {
                                textNum.setText("");
                            }
                        }
                        int num = 0;
                        if (chooseGoodstable != null) {
                            num = chooseGoodstable.getUsetime() / (10 - (lvlNum - 1) * 2);
                        }
                        long parseLong = Long.parseLong(str);
                        if (str.length() > 0) {
                            if (parseLong > num) {
                                textNum.setText(String.valueOf(num));
                            }
                        }
                    }

                    @Override
                    public void keyPressed(KeyEvent e) {
                    }

                    @Override
                    public void keyReleased(KeyEvent e) {
                        String str = textNum.getText();
                        if (str != null && !"".equals(str)) {
                            long parseLong = Long.parseLong(str);
                            int num = 0;
                            if (chooseGoodstable != null) {
                                num = chooseGoodstable.getUsetime() / (10 - (lvlNum - 1) * 2);
                            }
                            if (parseLong == num) {
                                return;
                            }
                            if (str.length() > 0) {
                                if (parseLong > num) {
                                    textNum.setText(String.valueOf(num));
                                }
                            }
                        }
                    }
                });
                (textNum.getDocument()).addDocumentListener(new DocumentListener() {
                    BigDecimal a = new BigDecimal(0);

                    @Override
                    public void removeUpdate(DocumentEvent e) {
                        String str = textNum.getText();
                        if (str != null && !str.equals("")) {
                            long parseLong = Long.parseLong(str);
                            if (parseLong > 0) {
                                if (chooseGoodstable != null) {
                                    int com = chooseGoodstable.getUsetime() / (10 - (lvlNum - 1) * 2);
                                    if (parseLong <= com) {
                                        money = new BigDecimal(parseLong * 1000000 * lvlNum);
                                    } else {
                                        money = new BigDecimal(com * 1000000 * lvlNum);
                                    }
                                }
                            }
                        } else {
                            money = a;
                        }
                    }

                    @Override
                    public void insertUpdate(DocumentEvent e) {
                        String str = textNum.getText();
                        if (str != null && !str.equals("")) {
                            long parseLong = Long.parseLong(str);
                            if (parseLong > 0) {
                                if (chooseGoodstable != null) {
                                    int com = chooseGoodstable.getUsetime() / (10 - (lvlNum - 1) * 2);
                                    if (parseLong <= com) {
                                        money = new BigDecimal(parseLong * 1000000 * lvlNum);
                                    } else {
                                        money = new BigDecimal(com * 1000000 * lvlNum);
                                    }
                                }
                            }
                        } else {
                            money = a;
                        }
                    }

                    @Override
                    public void changedUpdate(DocumentEvent e) {
                        String str = textNum.getText();
                        if (str != null && !str.equals("")) {
                            long parseLong = Long.parseLong(str);
                            if (Long.parseLong(str) > 0) {
                                if (chooseGoodstable != null) {
                                    int com = chooseGoodstable.getUsetime() / (10 - (lvlNum - 1) * 2);
                                    if (parseLong <= com) {
                                        money = new BigDecimal(parseLong * 1000000 * lvlNum);
                                    } else {
                                        money = new BigDecimal(com * 1000000 * lvlNum);
                                    }
                                }
                            }
                        } else {
                            money = a;
                        }
                    }
                });
                this.add(textNum);
            }
        } else {
            if (this.textNum == null) {
                (this.textNum = new JTextField("0")).setBounds(335, 357, 115, 16);
                this.textNum.setFont(UIUtils.TEXT_FONT1);
                this.textNum.setOpaque(false);
                this.textNum.setBorder(BorderFactory.createEmptyBorder());
                this.textNum.setCaretColor(Color.white);
                this.textNum.setForeground(Color.white);
                this.textNum.addKeyListener((KeyListener) new KeyListener() {
                    @Override
                    public void keyTyped(final KeyEvent e) {
                        final int charstr = e.getKeyChar();
                        final String str = GemRefineryMainJpanel.this.textNum.getText();
                        if (str.length() == 0) {
                            GemRefineryMainJpanel.this.textNum.setText("0");
                            return;
                        }
                        if (charstr < 48 || charstr > 57) {
                            e.consume();
                        }
                        if (str.length() == 1 && str.equals("0")) {
                            GemRefineryMainJpanel.this.textNum.setText("");
                        }
                        int num = 0;
                        if (GemRefineryMainJpanel.this.chooseGoodstable != null) {
                            num = GemRefineryMainJpanel.this.chooseGoodstable.getUsetime().intValue() / (10 - (GemRefineryMainJpanel.this.lvlNum - 1) * 2);
                        }
                        final long parseLong = Long.parseLong(str);
                        if (str.length() > 0 && parseLong > (long) num) {
                            GemRefineryMainJpanel.this.textNum.setText(String.valueOf(num));
                        }
                    }

                    @Override
                    public void keyPressed(final KeyEvent e) {
                    }

                    @Override
                    public void keyReleased(final KeyEvent e) {
                        final String str = GemRefineryMainJpanel.this.textNum.getText();
                        if (str != null && !"".equals(str)) {
                            final long parseLong = Long.parseLong(str);
                            int num = 0;
                            if (GemRefineryMainJpanel.this.chooseGoodstable != null) {
                                num = GemRefineryMainJpanel.this.chooseGoodstable.getUsetime().intValue() / (10 - (GemRefineryMainJpanel.this.lvlNum - 1) * 2);
                            }
                            if (parseLong == (long) num) {
                                return;
                            }
                            if (str.length() > 0 && parseLong > (long) num) {
                                GemRefineryMainJpanel.this.textNum.setText(String.valueOf(num));
                            }
                        }
                    }
                });
                this.textNum.getDocument().addDocumentListener((DocumentListener) new DocumentListener() {
                    BigDecimal a = new BigDecimal(0);

                    @Override
                    public void removeUpdate(final DocumentEvent e) {
                        final String str = GemRefineryMainJpanel.this.textNum.getText();
                        if (str != null && !str.equals("")) {
                            final long parseLong = Long.parseLong(str);
                            if (parseLong > 0L && GemRefineryMainJpanel.this.chooseGoodstable != null) {
                                final int com = GemRefineryMainJpanel.this.chooseGoodstable.getUsetime().intValue() / (10 - (GemRefineryMainJpanel.this.lvlNum - 1) * 2);
                                if (parseLong <= (long) com) {
                                    GemRefineryMainJpanel.this.money = new BigDecimal(parseLong * 1000000L * (long) GemRefineryMainJpanel.this.lvlNum);
                                } else {
                                    GemRefineryMainJpanel.this.money = new BigDecimal(com * 1000000 * GemRefineryMainJpanel.this.lvlNum);
                                }
                            }
                        } else {
                            GemRefineryMainJpanel.this.money = this.a;
                        }
                    }

                    @Override
                    public void insertUpdate(final DocumentEvent e) {
                        final String str = GemRefineryMainJpanel.this.textNum.getText();
                        if (str != null && !str.equals("")) {
                            final long parseLong = Long.parseLong(str);
                            if (parseLong > 0L && GemRefineryMainJpanel.this.chooseGoodstable != null) {
                                final int com = GemRefineryMainJpanel.this.chooseGoodstable.getUsetime().intValue() / (10 - (GemRefineryMainJpanel.this.lvlNum - 1) * 2);
                                if (parseLong <= (long) com) {
                                    GemRefineryMainJpanel.this.money = new BigDecimal(parseLong * 1000000L * (long) GemRefineryMainJpanel.this.lvlNum);
                                } else {
                                    GemRefineryMainJpanel.this.money = new BigDecimal(com * 1000000 * GemRefineryMainJpanel.this.lvlNum);
                                }
                            }
                        } else {
                            GemRefineryMainJpanel.this.money = this.a;
                        }
                    }

                    @Override
                    public void changedUpdate(final DocumentEvent e) {
                        final String str = GemRefineryMainJpanel.this.textNum.getText();
                        if (str != null && !str.equals("")) {
                            final long parseLong = Long.parseLong(str);
                            if (Long.parseLong(str) > 0L && GemRefineryMainJpanel.this.chooseGoodstable != null) {
                                final int com = GemRefineryMainJpanel.this.chooseGoodstable.getUsetime().intValue() / (10 - (GemRefineryMainJpanel.this.lvlNum - 1) * 2);
                                if (parseLong <= (long) com) {
                                    GemRefineryMainJpanel.this.money = new BigDecimal(parseLong * 1000000L * (long) GemRefineryMainJpanel.this.lvlNum);
                                } else {
                                    GemRefineryMainJpanel.this.money = new BigDecimal(com * 1000000 * GemRefineryMainJpanel.this.lvlNum);
                                }
                            }
                        } else {
                            GemRefineryMainJpanel.this.money = this.a;
                        }
                    }
                });
                this.add((Component) this.textNum);
            }
        }
        return this.textNum;
    }

    public void setTextNum(final JTextField textNum) {
        this.textNum = textNum;
    }

    public int getType() {
        return this.type;
    }

    public void setType(final int type) {
        this.type = type;
    }

    public ImageIcon getRightIcon() {
        return this.rightIcon;
    }

    public void setRightIcon(final ImageIcon rightIcon) {
        this.rightIcon = rightIcon;
    }

    public BigDecimal getMoney() {
        return this.money;
    }

    public void setMoney(final BigDecimal money) {
        this.money = money;
    }

    public RichLabel getRichMsg() {
        if (this.richMsg == null) {
            if (MyIsif.getStyle().equals("水墨UI")) {
                richMsg = new RichLabel("#R基础属性+0%，下一阶段属性#B+3%", UIUtils.TEXT_FONT1);
                richMsg.setBounds(55 + 230, 135, 230, 20);
            } else {
                (this.richMsg = new RichLabel("#R基础属性+0%，下一阶段属性#B+3%", UIUtils.TEXT_FONT1)).setBounds(275, 355, 230, 20);
            }
            this.add((Component) this.richMsg);
        }
        return this.richMsg;
    }

    public void setRichMsg(final RichLabel richMsg) {
        this.richMsg = richMsg;
    }

    public ImageIcon getGemBackImg() {
        return this.gemBackImg;
    }

    public void setGemBackImg(final ImageIcon gemBackImg) {
        this.gemBackImg = gemBackImg;
    }

    public GemRefineryBtn getBtnTrepanning() {
        if (this.btnTrepanning == null) {
            if (MyIsif.getStyle().equals("水墨UI")) {
                btnTrepanning = new GemRefineryBtn("skin/8100226/newbutton/K51.png", 1, 2, this);
                btnTrepanning.setBounds(55 + 2 * 92, 49, 90, 24);
            } else {
                (this.btnTrepanning = new GemRefineryBtn("inkImg/hongmu/2/unGemTrapper.png", 1, 2, this)).setBounds(207, 60, 86, 26);
            }
            this.add((Component) this.btnTrepanning);
        }
        return this.btnTrepanning;
    }

    public void setBtnTrepanning(final GemRefineryBtn btnTrepanning) {
        this.btnTrepanning = btnTrepanning;
    }

    public int getPage() {
        return this.page;
    }

    public void setPage(final int page) {
        this.page = page;
    }

    public ImageIcon getGemImg() {
        return this.gemImg;
    }

    public void setGemImg(final ImageIcon gemImg) {
        this.gemImg = gemImg;
    }

    public Goodstable getChooseGoodstable() {
        return this.chooseGoodstable;
    }

    public void setChooseGoodstable(final Goodstable chooseGoodstable) {
        this.chooseGoodstable = chooseGoodstable;
    }

    public int getLvlNum() {
        return this.lvlNum;
    }

    public void setLvlNum(final int lvlNum) {
        this.lvlNum = lvlNum;
    }

    public GemRefineryBtn getBtnCaozuoCompound() {
        if (this.btnCaozuoCompound == null) {
            if (MyIsif.getStyle().equals("水墨UI")) {
                btnCaozuoCompound = new GemRefineryBtn("skin/8100226/newbutton/B21.png", 1, 7, "合成", UIUtils.COLOR_WHITE2,
                        UIUtils.TEXT_HY16, this);
                btnCaozuoCompound.setBounds(334, 402, 79, 24);
            } else {
                (this.btnCaozuoCompound = new GemRefineryBtn("inkImg/hongmu/2/111.png", 1, 7, "合成", UIUtils.COLOR_BTNPUTONG2, UIUtils.TEXT_HY16, this)).setBounds(310, 424, 85, 72);
            }
            this.add((Component) this.btnCaozuoCompound);
        }
        return this.btnCaozuoCompound;
    }

    public void setBtnCaozuoCompound(final GemRefineryBtn btnCaozuoCompound) {
        this.btnCaozuoCompound = btnCaozuoCompound;
    }

    public GemRefineryBtn getBtnCaozuoDisassembly() {
        if (this.btnCaozuoDisassembly == null) {
            if (MyIsif.getStyle().equals("水墨UI")) {
                btnCaozuoDisassembly = new GemRefineryBtn("skin/8100226/newbutton/B21.png", 1, 8, "拆卸", UIUtils.COLOR_WHITE2,
                        UIUtils.TEXT_HY16, this);
                btnCaozuoDisassembly.setVisible(false);
                btnCaozuoDisassembly.setBounds(396, 429, 79, 24);
            } else {
                (this.btnCaozuoDisassembly = new GemRefineryBtn("inkImg/hongmu/2/111.png", 1, 8, "拆卸", UIUtils.COLOR_BTNPUTONG2, UIUtils.TEXT_HY16, this)).setVisible(false);
                this.btnCaozuoDisassembly.setBounds(372, 424, 85, 72);
            }

            this.add((Component) this.btnCaozuoDisassembly);
        }
        return this.btnCaozuoDisassembly;
    }

    public void setBtnCaozuoDisassembly(final GemRefineryBtn btnCaozuoDisassembly) {
        this.btnCaozuoDisassembly = btnCaozuoDisassembly;
    }

    public Goodstable getTwoGoodstable() {
        return this.twoGoodstable;
    }

    public void setTwoGoodstable(final Goodstable twoGoodstable) {
        this.twoGoodstable = twoGoodstable;
    }

    public int getGemNum() {
        return this.gemNum;
    }

    public void setGemNum(final int gemNum) {
        this.gemNum = gemNum;
    }

    public int getGemBackNum() {
        return this.gemBackNum;
    }

    public void setGemBackNum(final int gemBackNum) {
        this.gemBackNum = gemBackNum;
    }

    class MListener implements MouseListener {
        private int numPlace;

        public MListener(final int numPlace) {
            this.numPlace = numPlace;
        }

        @Override
        public void mouseClicked(final MouseEvent e) {
        }

        @Override
        public void mousePressed(final MouseEvent e) {
            if (this.numPlace < 0) {
                if (this.numPlace == -1 && GemRefineryMainJpanel.this.chooseGoodstable != null) {
                    GemRefineryMainJpanel.this.chooseGoodstable = null;
                    GemRefineryMainJpanel.this.twoGoodstable = null;
                }
            } else {
                final Goodstable goodstable = GemRefineryMainJpanel.this.getChooseGoods(this.numPlace);
                if (goodstable != null) {
                    GemRefineryMainJpanel.this.addChooseGoods(goodstable);
                }
            }
        }

        @Override
        public void mouseReleased(final MouseEvent e) {
        }

        @Override
        public void mouseEntered(final MouseEvent e) {
            if (this.numPlace < 0) {
                if (this.numPlace == -1) {
                    if (GemRefineryMainJpanel.this.chooseGoodstable != null) {
                        ZhuFrame.getZhuJpanel().creatgoodtext(GemRefineryMainJpanel.this.chooseGoodstable);
                    }
                } else if (this.numPlace == -2 && GemRefineryMainJpanel.this.twoGoodstable != null) {
                    ZhuFrame.getZhuJpanel().creatgoodtext(GemRefineryMainJpanel.this.twoGoodstable);
                }
            } else {
                final Goodstable goodstable = GemRefineryMainJpanel.this.getChooseGoods(this.numPlace);
                if (goodstable != null) {
                    ZhuFrame.getZhuJpanel().creatgoodtext(goodstable);
                    MessagrFlagUntil.setMouse(MessagrFlagUntil.MOUSE12);
                }
            }
        }

        @Override
        public void mouseExited(final MouseEvent e) {
            MessagrFlagUntil.setMouse(MessagrFlagUntil.MOUSE1);
            TestpackJframe.getTestpackJframe().getJpac().ClearText();
            ZhuFrame.getZhuJpanel().cleargoodtext();
        }
    }
}
